﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        HotKeys h = new HotKeys();
        [DllImport("user32.dll", EntryPoint = "keybd_event", SetLastError = true)]
        public static extern void keybd_event(Keys bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
        public Form1()
        {
            InitializeComponent();
          // this.BackColor = Color.White;
          //  this.TransparencyKey = Color.White;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("注册成功");
            keybd_event(Keys.Enter, 0, 0, 0);
            keybd_event(Keys.A, 0, 0, 0);

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            keybd_event(Keys.Enter, 0, 0, 0);
            keybd_event(Keys.A, 0, 0, 0);
            // SendKeys.Send("ABC");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            //注册//这里注册了Ctrl+Alt+E 快捷键
            h.Regist(this.Handle, (int)HotKeys.HotkeyModifiers.Control + (int)HotKeys.HotkeyModifiers.Alt, Keys.E, CallBack);
            MessageBox.Show("注册成功");

        }
        //按下快捷键时被调用的方法
        public void CallBack()
        {
            //SendKeys.Send("{ENTER}");
            MessageBox.Show("快捷键被调用！");
        }
        protected override void WndProc(ref Message m)
        {
            //窗口消息处理函数
            h.ProcessHotKey(m);
            base.WndProc(ref m);
        }
        private void button3_Click(object sender, EventArgs e)
        {
            h.UnRegist(this.Handle, CallBack);
            MessageBox.Show("卸载成功");
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
        }
    }
}
